package com.chixing.day11_exception;

import com.chixing.day11_exception.work.ListNode;

/*
    链式结构的容器，用于存放字符串
*/
public class LinkString {

    private Node first;
    private Node last;
    private int size;//已有元素个数
    private int modifierCount;//整个该容器结构上发生修改的次数,结构上（添加、删除元素）
                              // 防止快速迭代失败（防止在遍历的时候，有元素删除或添加 而导致 遍历不正确）

    public void add(String element){
        if (first ==null){
            first = new Node(null,element,null);
            last = first;
        }
        else {
            Node olLast = last;
            last = new Node(olLast,element,null);
            olLast.next = last;
        }
        size++;
        modifierCount++;
    }

    public class Node{
        String value;//元素值本身
        Node previous;//前一个元素
        Node next;//后一个元素

        public Node(Node previous,String value,Node next){
            this.previous = previous;
            this.value = value;
            this.next = next;
        }
    }

    public void show(){
        if (first!=null){
            Node node = first;
            while (node != null){
                System.out.println(node.value);
                node = node.next;
            }
        }

    }


    /*public  LinkString removeNthFromEnd(LinkString head, int n) {
        int count = 0;
        if (first!=null)
            head = first;
        while (head!=null){
            head = head.next;
            count++;
            if (count==size-n){
                Node old = first;
                first = new Node(old, head.next.value, null);
                old.next = first;
            }
        }
        return head;
    }*/

    public static void main(String[] args) {

    }

}
